/* NOTICE
 
    Jim - the Java Image Manager, copyright (c) 2005 - 2007 Grant Gardner 
 
    Jim is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Jim is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
    In addition, as a special exception, you are permitted to link this code
    with the 3rd party libraries required to compile this file and to
    distribute a linked combination including them. You must obey the
    GNU General Public License in all respects for all of the code except for
    those 3rd party libraries that are licenced under terms incompatible with the
    GNU General Public License.  
 
 
 NOTICE */

/*
 * Created by dnoakes on 27-Nov-2002 10:12:05 using IntelliJ IDEA.
 */

package au.com.lastweekend.jim.io.exif.makernote.olympus;

import au.com.lastweekend.jim.io.metadata.Directory;
import au.com.lastweekend.jim.io.metadata.MetadataException;
import au.com.lastweekend.jim.io.metadata.AbstractTagDescriptor;

/**
 * 
 * 
 * 
 * @version $Id: OlympusMakernoteDescriptor.java,v 1.2 2005/06/09 11:15:38 ggardner Exp $
 * @author <a href="mailto:grant@lastweekend.com.au"> <Grant Gardner> </a>
 */
public class OlympusMakernoteDescriptor extends AbstractTagDescriptor {

    public OlympusMakernoteDescriptor(Directory directory) {

        super(directory);
    }

    @Override
    public String getDescription(int tagType) throws MetadataException {

        switch (tagType) {
            case OlympusMakernoteDirectory.TAG_OLYMPUS_SPECIAL_MODE :
                return getSpecialModeDescription();
            case OlympusMakernoteDirectory.TAG_OLYMPUS_JPEG_QUALITY :
                return getJpegQualityDescription();
            case OlympusMakernoteDirectory.TAG_OLYMPUS_MACRO_MODE :
                return getMacroModeDescription();
            case OlympusMakernoteDirectory.TAG_OLYMPUS_DIGI_ZOOM_RATIO :
                return getDigiZoomRatioDescription();
            default :
                return getDirectory().getString(tagType);
        }
    }

    private String getDigiZoomRatioDescription() throws MetadataException {

        if (!getDirectory().containsTag(OlympusMakernoteDirectory.TAG_OLYMPUS_DIGI_ZOOM_RATIO)) {
            return null;
        }
        int value = getDirectory().getInt(OlympusMakernoteDirectory.TAG_OLYMPUS_DIGI_ZOOM_RATIO);
        switch (value) {
            case 0 :
                return "Normal";
            case 2 :
                return "Digital 2x Zoom";
            default :
                return "Unknown (" + value + ")";
        }
    }

    private String getMacroModeDescription() throws MetadataException {

        if (!getDirectory().containsTag(OlympusMakernoteDirectory.TAG_OLYMPUS_MACRO_MODE)) {
            return null;
        }
        int value = getDirectory().getInt(OlympusMakernoteDirectory.TAG_OLYMPUS_MACRO_MODE);
        switch (value) {
            case 0 :
                return "Normal (no macro)";
            case 1 :
                return "Macro";
            default :
                return "Unknown (" + value + ")";
        }
    }

    private String getJpegQualityDescription() throws MetadataException {

        if (!getDirectory().containsTag(OlympusMakernoteDirectory.TAG_OLYMPUS_JPEG_QUALITY)) {
            return null;
        }
        int value = getDirectory().getInt(OlympusMakernoteDirectory.TAG_OLYMPUS_JPEG_QUALITY);
        switch (value) {
            case 1 :
                return "SQ";
            case 2 :
                return "HQ";
            case 3 :
                return "SHQ";
            default :
                return "Unknown (" + value + ")";
        }
    }

    private String getSpecialModeDescription() throws MetadataException {

        if (!getDirectory().containsTag(OlympusMakernoteDirectory.TAG_OLYMPUS_SPECIAL_MODE)) {
            return null;
        }
        int[] values = getDirectory().getIntArray(OlympusMakernoteDirectory.TAG_OLYMPUS_SPECIAL_MODE);
        StringBuffer desc = new StringBuffer();
        switch (values[0]) {
            case 0 :
                desc.append("Normal picture taking mode");
                break;
            case 1 :
                desc.append("Unknown picture taking mode");
                break;
            case 2 :
                desc.append("Fast picture taking mode");
                break;
            case 3 :
                desc.append("Panorama picture taking mode");
                break;
            default :
                desc.append("Unknown picture taking mode");
                break;
        }
        desc.append(" - ");
        switch (values[1]) {
            case 0 :
                desc.append("Unknown sequence number");
                break;
            case 1 :
                desc.append("1st in a sequnce");
                break;
            case 2 :
                desc.append("2nd in a sequence");
                break;
            case 3 :
                desc.append("3rd in a sequence");
                break;
            default :
                desc.append(values[1]);
                desc.append("th in a sequence");
                break;
        }
        switch (values[2]) {
            case 1 :
                desc.append("Left to right panorama direction");
                break;
            case 2 :
                desc.append("Right to left panorama direction");
                break;
            case 3 :
                desc.append("Bottom to top panorama direction");
                break;
            case 4 :
                desc.append("Top to bottom panorama direction");
                break;
            default : // do nothing
        }
        return desc.toString();
    }

    @Override
    public boolean isTagUpdateable(int tagType) {

        return false;
    }
}